<?php

/**
 * @version 1.0.0
 * @package ResMania 1.0.0
 * @copyright (C) 2010 resmania.com
 * @license GPL, http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.installer.installer');
$db = & JFactory::getDBO();
$installer = new JInstaller;

if (version_compare(JVERSION, '1.6.0', 'ge')) {
    $source = dirname(__FILE__);
} else {
    $source = $this->parent->getPath('source');
}
$modulePath = $source . DS . "modules";

$installer->install($modulePath . DS . "cart");
$installer->install($modulePath . DS . "search");
$installer->install($modulePath . DS . "cpanel");

// publish the dashbord icon
$db =& JFactory::getDBO();
$query = "SELECT id FROM #__modules WHERE module='mod_resmania'";
$db->setQuery($query);
$id = $db->loadResult();

if (!(int)$id){
    $sql = "INSERT INTO `#__modules`(`title`,`content`,`ordering`,`position`,`checked_out`,`checked_out_time`,`published`,`module`,`numnews`,`access`,`showtitle`,`params`,`iscore`,`client_id`,`control`) VALUES ('ResMania Joomla Control Panel Icon Module','',0,'icon',0,'0000-00-00 00:00:00',1,'mod_resmania',0,2,1,'',0,1,'');";
} else {
    $sql = "UPDATE `#__modules` SET `published`='1', position='icon' WHERE id='".$id."'";
}
$db->setQuery($sql);
$db->Query();